package protocol.JT808_2011;

public class Handle808_2011JT07 implements IHandle808_2011JT {

    @Override
    public String handle(JT808_2011Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x00:
                return handle0700(cmd);
            case 0x01:
                return handle0701(cmd);
            case 0x02:
                return handle0702(cmd);
            default:
                return "808-2011:未匹配的命令字"+(cmd.readOrder()+","+cmd.subOrder());
        }
    }

    private String handle0702(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:行驶记录数据上传");
        builder.append("\r\n");

        builder.append("驾驶员姓名："+cmd.readString(cmd.readInt()));
        builder.append("\r\n");
        builder.append("驾驶员身份证编码："+cmd.readString(20));
        builder.append("\r\n");
        builder.append("驾驶员从业资格证编码："+cmd.readString(40));
        builder.append("\r\n");
        builder.append("发证机构："+cmd.readString(cmd.readInt()));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0701(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:行驶记录数据上传");
        builder.append("\r\n");
        int size = cmd.readDWORD();
        builder.append("电子运单长度："+size);
        builder.append("\r\n");
        builder.append("电子运单内容："+cmd.readBCD(size));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0700(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:行驶记录数据上传");
        builder.append("\r\n");
        builder.append("应答流水号："+cmd.readBCD(2));
        builder.append("\r\n");
        builder.append("命令字："+cmd.readBCD(1));
        builder.append("\r\n");

        builder.append("数据："+cmd.readBCD(cmd.leftSize()));
        builder.append("\r\n");
        return builder.toString();
    }
}
